﻿using System;
using System.Collections.Generic;
using System.Text;
using DepInnerTask.Common.Interface;
using DepInnerTask.Common.Entity;
using IBatisNet.DataMapper;
using Common.Service;
using System.Collections;
using Common.Logging;
using DepInner;

namespace DepInnerTask.Logic
{
    class ExceptionLogLogic:IExceptionLog
    {
        public IList GetList(string where, int start, int limit, out int count,string flag)
        {
            Hashtable table = new Hashtable();
            //查询条件的形式 为 [表字段名=参数值; ...]
            if (!String.IsNullOrEmpty(where))
            {
                where = where.TrimEnd('△');//格式化 条件 语句
                string[] strWheres = where.Split('△');//
                for (int i = 0; i < strWheres.Length; i++)
                {
                    string str = strWheres[i];
                    string[] strParems = str.Split('▽');
                    table.Add(strParems[0], strParems[1]);//参数 将参数信息添加到hashtable中
                }
            }
            IList list = null;
            if (flag == "1")//异常终止
            {
                string ss = DataHelper.Instance().GetSqlString("GetLogListByCondition", table);
                 list = DataHelper.Instance().GetList("GetLogListByCondition", table, start, limit);
            }
            else if (flag == "2")//异常拒绝
            {
                string ss = DataHelper.Instance().GetSqlString("GetLogListByCondition1", table);
                list = DataHelper.Instance().GetList("GetLogListByCondition1", table, start, limit);
            }
            count = list.Count;

            return list;
        }

        public ExceptionLogEntity Get(string taskId)
        {
            return DataHelper.Instance().Get<ExceptionLogEntity>("GetLogListByID", taskId);
        }

        public void Insert(ExceptionLogEntity entity)
        {
            DataHelper.Instance().Insert("InsertExceptionLog", entity);
        }

        public void Update(ExceptionLogEntity entity)
        {
            DataHelper.Instance().Update("UpdateLogByID", entity);
        }

        public bool Exists(string taskId)
        {
            throw new NotImplementedException();
        }

        public void Delete(string taskId)
        {
            DataHelper.Instance().Delete("TaskLogic_Delete", taskId);
        }
    }
}
